﻿using Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System.Linq;

namespace Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        private readonly ApiDBContext _context;

        public ValuesController(ApiDBContext context)
        {
            _context = context;
        }

        [HttpGet]
        public Result Get()
        {
            Result result = new Result();

            var resulrData = _context.EntityBase.ToList<EntityBase>();
            result.Data = resulrData;
            result.Code = 200;
            result.Author = "44274941@qq.com";
            return result;
        }

        [HttpGet("{Id}/{userName}")]
        public Result Get(Guid Id,string userName)
        {
            Result result = new Result();

            EntityBase? resulrData = _context.EntityBase.Where(w => w.Id == Id).FirstOrDefault<EntityBase>();
            if (resulrData == null)
            {
                result.Code = 404;
            }
            else
            {
                result.Code = 200;
                result.Data = resulrData;
            }
            return result;
        }

        [HttpGet("like/{name}")]
        public List<car> GetCarLikeName(string name)
        {
            List<Car> cars = new List<Car>();


        }
    }
}
